using System;
using ProtoModels;
using UnityEngine;

public class PlayerMood
{
	public delegate void OnSave();

	private OnSave onSave;

	private PlayerModel model;

	private const float maxMood = 1f;

	private const float minMood = 0f;

	private const float moodLossRatePerDay = 0.5f;

	public PlayerMood(PlayerModel model, OnSave onSave)
	{
		this.model = model;
		this.onSave = onSave;
	}

	public void ReloadModel(PlayerModel model)
	{
		this.model = model;
	}

	public float GetMood()
	{
		UpdateMood();
		return model.mood;
	}

	public void UpdateMood(float moodToAdd = 0f)
	{
		LooseMoodWithTime();
		model.mood = Mathf.Min(1f, model.mood + moodToAdd);
		model.lastTimeMoodBoost = DateTime.Now.Ticks;
		DoOnSave();
	}

	private void LooseMoodWithTime()
	{
		DateTime value = new DateTime(model.lastTimeMoodBoost);
		float num = (float)DateTime.Now.Subtract(value).TotalDays;
		model.mood = Mathf.Max(0f, model.mood - num * 0.5f);
	}

	private void DoOnSave()
	{
		if (onSave != null)
		{
			onSave();
		}
	}
}
